package com.healthmgmt.app.service.impl;

import com.healthmgmt.app.domain.Doctor;
import com.healthmgmt.app.mapper.DoctorMapper;
import com.healthmgmt.app.service.IDoctorService;
import com.healthmgmt.common.service.ObjectStorageService;
import com.healthmgmt.common.utils.DateUtils;
import com.healthmgmt.common.utils.SecurityUtils;
import com.healthmgmt.common.utils.file.FileUploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 医生Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-06-29
 */
@Service
public class DoctorServiceImpl implements IDoctorService
{
    @Autowired
    private DoctorMapper doctorMapper;

    @Resource
    private ObjectStorageService objectStorageService;

    /**
     * 查询医生
     * 
     * @param doctorId 医生主键
     * @return 医生
     */
    @Override
    public Doctor selectDoctorByDoctorId(Long doctorId)
    {
        return doctorMapper.selectDoctorByDoctorId(doctorId);
    }

    /**
     * 查询医生列表
     * 
     * @param doctor 医生
     * @return 医生
     */
    @Override
    public List<Doctor> selectDoctorList(Doctor doctor)
    {
        return doctorMapper.selectDoctorList(doctor);
    }

    /**
     * 新增医生
     * 
     * @param doctor 医生
     * @return 结果
     */
    @Override
    public int insertDoctor(Doctor doctor)
    {
        doctor.setUserId(SecurityUtils.getUserId());
        doctor.setCreateTime(DateUtils.getNowDate());
        try {
            String url = objectStorageService.uploadToOss(FileUploadUtils.generateAndUploadQrCode("2025062901", 200, 150));
            doctor.setQrCode(url);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return doctorMapper.insertDoctor(doctor);
    }

    /**
     * 修改医生
     * 
     * @param doctor 医生
     * @return 结果
     */
    @Override
    public int updateDoctor(Doctor doctor)
    {
        doctor.setUpdateTime(DateUtils.getNowDate());
        return doctorMapper.updateDoctor(doctor);
    }

    /**
     * 批量删除医生
     * 
     * @param doctorIds 需要删除的医生主键
     * @return 结果
     */
    @Override
    public int deleteDoctorByDoctorIds(Long[] doctorIds)
    {
        return doctorMapper.deleteDoctorByDoctorIds(doctorIds);
    }

    /**
     * 删除医生信息
     * 
     * @param doctorId 医生主键
     * @return 结果
     */
    @Override
    public int deleteDoctorByDoctorId(Long doctorId)
    {
        return doctorMapper.deleteDoctorByDoctorId(doctorId);
    }
}
